import Vue from 'vue'
import VueRouter from 'vue-router'
// import Reports from '../components/report/Reports'
const Reports = () => import(/* webpackChunkName:"report" */ '../components/report/Reports.vue')
// import Order from '../components/order/Order'
const Order = () => import(/* webpackChunkName:"order" */ '../components/order/Order.vue')
// import Add from '../components/goods/AddGoods'
const Add = () => import(/* webpackChunkName:"goods" */ '../components/goods/AddGoods.vue')
// import List from '../components/goods/List'
const List = () => import(/* webpackChunkName:"goods" */ '../components/goods/List.vue')
// import Params from '../components/goods/Params'
const Params = () => import(/* webpackChunkName:"goods" */ '../components/goods/Params.vue')
// import GoodsCate from '../components/goods/Cate'
const GoodsCate = () => import(/* webpackChunkName:"goods" */ '../components/goods/Cate.vue')
// import Roles from '../components/rights/Roles'
const Roles = () => import(/* webpackChunkName:"rights" */ '../components/rights/Roles.vue')
// import Rights from '../components/rights/Rights'
const Rights = () => import(/* webpackChunkName:"rights" */ '../components/rights/Rights.vue')
// import User from '../components/user/Users'
const User = () => import(/* webpackChunkName:"user" */ '../components/user/Users.vue')
// import Welcome from '../components/Welcome'
const Welcome = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Welcome.vue')
// import Home from '../components/Home'
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Home.vue')
// 导入登录组件
// import Login from '../components/Login'
const Login = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Login.vue')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      {
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/users',
        component: User
      },
      {
        path: '/rights',
        component: Rights
      },
      {
        path: '/roles',
        component: Roles
      },
      {
        path: '/categories',
        component: GoodsCate
      },
      {
        path: '/params',
        component: Params
      },
      {
        path: '/goods',
        component: List
      },
      {
        path: '/goods/add',
        component: Add
      },
      {
        path: '/orders',
        component: Order
      },
      {
        path: '/reports',
        component: Reports
      }
    ]

  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const token = window.sessionStorage.getItem('token')
  if (!token) return next('/login')
  next()
})

export default router
